﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Presentation
{
    public partial class OptionKey : Form
    {
        public OptionKey()
        {
            InitializeComponent();
            _OK = false;
        }

        private int _DelayDefault;

        public int DelayDefault
        {
            get { return _DelayDefault; }
            set { _DelayDefault = value; }
        }
        private int _Loop;

        public int Loop
        {
            get { return _Loop; }
            set
            {
                _Loop=value;
            }
        }
        private string _Description;

        public string Description
        {
            get { return _Description; }
            set { _Description = value; }
        }

        private bool _OK;

        private void cmdSetDelay_Click(object sender, EventArgs e)
        {
            SetDelay _SetDelay = new SetDelay();
            nudDelay.Value = _SetDelay.ShowSetDelay(Convert.ToInt32(nudDelay.Value));
        }

        public void ShowOption()
        {
            nudDelay.Value = _DelayDefault;
            CheckLoop(_Loop);
            rtxtDescription.Text = _Description;
            _OK = false;
            this.ShowDialog();
            if (_OK)
            {
                _DelayDefault = Convert.ToInt32(nudDelay.Value);
                if (rbOnce.Checked)
                    _Loop = 1;
                else if (rbMany.Checked)
                    _Loop = Convert.ToInt32(nudLoop.Value);
                else
                    _Loop = -1;
                _Description = rtxtDescription.Text;
            }
        }

        private void cmdOK_Click(object sender, EventArgs e)
        {
            _OK = true;
            this.Close();
        }

        private void cmdCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void rb_CheckedChanged(object sender, EventArgs e)
        {
            if (rbMany.Checked)
                nudLoop.Enabled = true;
            else
                nudLoop.Enabled = false;
        }

        private void CheckLoop(int Loop)
        {
            if (Loop == 1)
                rbOnce.Checked = true;
            else if (Loop == -1)
                rbForever.Checked = true;
            else
            {
                rbMany.Checked = true;
                nudLoop.Value = Loop;
            }
        }
    }
}
